#include <pybind11/pybind11.h>
#include "Block.h"
#include "Utility.h"

namespace py = pybind11;


PYBIND11_MODULE(fs, m) {
    py::class_<Block>(m, "Block")
        .def_static("from_size", [](int size){
            return std::unique_ptr<Block>(new Block(size)); })
        .def_static("from_byte", [](int c, int capacity, int repeat) {
	        if (c < 0 || c > 255) { throw py::value_error("c is not ascii"); }
	        if (repeat > capacity) { throw py::value_error("repeat > capacity"); }
            return std::unique_ptr<Block>(new Block(c, capacity, repeat)); },
	    py::arg("c"), py::arg("capacity") = 4096, py::arg("repeat") = 1) 
        .def("size", &Block::size)
        .def("data", [](Block &b) {
            return py::memoryview::from_memory(b.data(), b.size(), false); })
    ;

    py::class_<BitUtility>(m, "BitUtility")
        .def_static("bitWidth", &BitUtility::bitWidth)
        .def_static("align_greater_equal", &BitUtility::alignGreaterEqual)
    ;
}

